package findMaxAverage;

public class Solution {
    public double findMaxAverage(int[] nums, int k) {
        int sum = 0;
        for (int i = 0; i < k; i++) {
            sum+=nums[i];
        }
        int res = sum;
        int l = 1;
        int r = k;
        while(r<nums.length){
            sum-=nums[l++];
            sum+=nums[r++];
            res = Math.max(sum,res);
        }
        return res*1.0/k;
    }
}
